#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-10 9:28 上午
# @Author  : yangdy
# @File    : 2020-08-08.1.5468.第k个缺失的正整数
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def findKthPositive(self, arr: List[int], k: int) -> int:
        ans = 0
        if not arr:
            return ans

        la = len(arr)
        if arr[0] > k:
            return k
        else:
            k -= arr[0] - 1
        for i in range(1, la):
            if arr[i] - arr[i-1] > k:
                ans = arr[i-1] + k
                k = 0
                break
            else:
                k -= arr[i] - arr[i-1] - 1
        if k > 0:
            ans = arr[la-1] + k

        return ans


questions = [
    ([2, 3, 4, 7, 11], 5),
    ([1, 2, 3, 4], 2),
]

work(questions, lambda q: Solution().findKthPositive(q[0], q[1]))

